//
// Created by jsjxsy on 2022/8/19.
//operator type() const;
//
#include <iostream>
using namespace std;
class SmallInt {
 public:
  SmallInt(int val = 0) : val(val) {
    if (val < 0 || val > 255) {
      throw std::out_of_range("bad smallInt value");
    }
  }
  SmallInt &operator+(const SmallInt &other);
  SmallInt &operator+(int value);
  operator int() {
    cout << "operator int()" << endl;
    return val;
  }
  short int getValue() {
    return val;
  }
 private:
  short int val;
};
SmallInt &SmallInt::operator+(const SmallInt &other) {
  cout << "operator+" << endl;
  val = val + other.val;
  return *this;
}
SmallInt &SmallInt::operator+(int value) {
  val = val + value;
  return *this;
}
int main() {
  SmallInt t1;
  t1 = 3;
  t1 = t1 + 4;
  cout << "t3=" << t1.getValue() << endl;
  SmallInt t2;
  t2 = 5;
  SmallInt t3;
  t3 = t2 + t1;
  cout << "t3=" << t3.getValue() << endl;
  return 0;
}
